
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Dialogs 1.2

Dialog {
    id: root

    onButtonClicked: {
        console.log("clicked button " + clickedButton)
        if(clickedButton === StandardButton.Ok) {
            root.accepted();
        }
        else {
            textInput.text = "";
        }
        root.hide();
    }

    /*
    onAccepted: (clickedButton == StandardButton.Ok ? "(OK)" : (clickedButton == StandardButton.Retry ? "(Retry)" : "(Ignore)"))
    onRejected: (clickedButton == StandardButton.Close ? "(Close)" : (clickedButton == StandardButton.Abort ? "(Abort)" : "(Cancel)"))
    
    onHelp: lastChosen.text = "Yelped for help!"
    onYes: lastChosen.text = (clickedButton == StandardButton.Yes ? "Yeessss!!" : "Yes, now and always")
    onNo: lastChosen.text = (clickedButton == StandardButton.No ? "Oh No." : "No, no, a thousand times no!")
    onApply: lastChosen.text = "Apply"
    onReset: lastChosen.text = "Reset"
    */

    standardButtons: StandardButton.Cancel | StandardButton.Ok
    property string inputText: textInput.text

    signal accepted
    signal closed

    height: 200
    width: 320

    function setModal(enable) {
        modality = enable ? 1 : 0;
    }
    function setTitle(text) {
        title = text;
    }

    function show(text) {
        dialogText.text = text;
        setHeight(200);
        setWidth(320);
        textInput.opacity = 0;
        root.open();
    }

    function showWithInput(text) {
        show(text);
        textInput.opacity = 1;
        textInput.focus = true;
        textInput.text = "";
    }

    function hide() {
        textInput.focus = false;
        root.closed();
    }
    
    Text {
        id: dialogText
        text: "Hello world!"
        font.pointSize: 10
        anchors { leftMargin: 10 }
        z: 1000
    }

    Rectangle {
        anchors {
            leftMargin: 10
            top: dialogText.bottom
        }
        z: 1000
        color: "#ffffff"
        border.width: 1
        border.color: "#000000"
        height: 20
    }

    TextEdit {
        id: textInput
        text: ""
        font.pointSize: 10
        anchors {
            leftMargin: 10
            top: dialogText.bottom
        }

        z: 1000
        width: parent.width
        focus: true
    }
}

